const { News } = require('../../../model/news');
// 引入分页模块
const pagination = require('mongoose-sex-page')
// const { decodeToken } = require('../../../middleGuard/jwt')

module.exports = async (req, res) => {
  const { index, size, state = null } = req.query
  const query = {}
  // query.user = decodeToken(req.headers.authorization).userId
  if (typeof state !== null && state >= 0) {
      query.state = Number(state)
  }
  console.log(state)
  console.log(query)
  const list = await pagination(News).find(query).page(index).size(size).populate('category').populate('user', 'avatar username nickname').exec()
  res.json({
      data: list
  })
}